// Package registerinit -----------------------------
// @file      : registerInit.go
// @author    : WuZhouHai
// @contact   : wzh200x@126.com
// @time      : 2024/1/3 19:06
// @desc      :
// -------------------------------------------
package main

import (
	"phoenix/apps/examples/phoenix_app_dwys/config"
	"phoenix/apps/examples/phoenix_app_dwys/defines"
	"phoenix/apps/examples/phoenix_app_dwys/defines/entityType"
	"phoenix/apps/examples/phoenix_app_dwys/entities"
	"phoenix/apps/examples/phoenix_app_dwys/entities/module/avatar"
	"phoenix/apps/examples/phoenix_app_dwys/model/entity"
	avatar2 "phoenix/apps/examples/phoenix_app_dwys/model/entityModule/avatar"
	"phoenix/apps/examples/phoenix_app_dwys/protocol/golang/protos"
	"phoenix/apps/examples/phoenix_app_dwys/webHandle/hello"
	"phoenix/phoenix/defines/opcode"
	"phoenix/phoenix/register"
	"reflect"
)

func init() {
	registerProtocol()
	registerRouter()
	registerConfig()
	registerEntityModuleModel()
	registerEntityModule()
	initObjects()
	initModel()
}

func registerRouter() {
	register.RegisterRouterGroup("/", hello.NewHello)
}

func registerConfig() {
	register.RegisterLogicConfig(defines.Config_ChooseCard, config.NewCardConfig)
	register.RegisterLogicConfig(defines.Config_CardGroup, config.NewCardGroupConfig)
	register.RegisterLogicConfig(defines.Config_AllRoom, config.NewAllRoomConfig)
	register.RegisterLogicConfig(defines.Config_RoomShaoKaoPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomShaoKaoPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomShaoKaoUpLevel, config.NewRoomUpLevelConfig)
	register.RegisterLogicConfig(defines.Config_RoomNaiChaPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomNaiChaPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomNaiChaUpLevel, config.NewRoomUpLevelConfig)
	register.RegisterLogicConfig(defines.Config_RoomMaLaTangPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomMaLaTangPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomMaLaTangUpLevel, config.NewRoomUpLevelConfig)
	register.RegisterLogicConfig(defines.Config_RoomWaWaJiPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomWaWaJiPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomWaWaJiUpLevel, config.NewRoomUpLevelConfig)
	register.RegisterLogicConfig(defines.Config_RoomZhajiPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomZhajiPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomZhajiUpLevel, config.NewRoomUpLevelConfig)
	register.RegisterLogicConfig(defines.Config_RoomGeTingPmt, config.NewRoomPmtConfig)
	register.RegisterLogicConfig(defines.Config_RoomGeTingPmtType, config.NewRoomPmtTypeConfig)
	register.RegisterLogicConfig(defines.Config_RoomGeTingUpLevel, config.NewRoomUpLevelConfig)
}

func registerProtocol() {
	registerC2S()
	registerS2C()
}

func registerEntityModuleModel() {
	register.RegisterModelModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_Resources,
		avatar2.NewAvatarResourcesModel)
	register.RegisterModelModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_AllRoom,
		avatar2.NewAvatarAllRoomModel)
	register.RegisterModelModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_RoomPmt,
		avatar2.NewAvatarRoomPmtModel)
}

func registerEntityModule() {
	register.RegisterEntityModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_Resources,
		avatar.NewAvatarResourceModule)
	register.RegisterEntityModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_AllRoom,
		avatar.NewAvatarAllRoomModule)
	register.RegisterEntityModule(entityType.EntityName_Avatar, defines.ModuleName_Avatar_RoomPmt,
		avatar.NewAvatarRoomPmtModule)
}

func initObjects() {
	// 注册对象池
	register.RegisterObjects(entityType.EntityName_Avatar, entities.AvatarObjectCreate, entities.AvatarObjectDestroy)
}

func initModel() {
	// 注册实体数据模型
	register.RegisterModel(entityType.EntityName_Avatar, entity.NewAvatarModel)
}

func registerC2S() {
	// 客户端到服务器消息
	register.RegisterSocketHandler(defines.Opcode_CS_GET_RESOURCES, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_GetResources{}), "OnGetResources", "")
	register.RegisterSocketHandler(defines.Opcode_CS_GET_ROOM_INFO, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_GetRoomInfo{}), "OnGetRoomInfo", "")
	register.RegisterSocketHandler(defines.Opcode_CS_GET_ROOM_PMT, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_GetRoomPmtInfo{}), "OnGetRoomPmtInfo", "")
	register.RegisterSocketHandler(defines.Opcode_CS_ROOM_PMT_UP_LEVEL, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_UpRoomPmtLevel{}), "OnRoomPmtUpLevel", "")
	register.RegisterSocketHandler(defines.Opcode_CS_ROOM_UP_CY_LEVEL, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_UpRoomCyLevel{}), "OnRoomUpCyLevel", "")
	register.RegisterSocketHandler(defines.Opcode_CS_HARVEST_RESOURCES, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_HarvestResources{}), "OnHarvestResources", "")
	register.RegisterSocketHandler(defines.Opcode_CS_ACTIVE_ROOM, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.C2S_ActiveRoom{}), "OnActiveRoom", "")
}

func registerS2C() {
	// 服务器到客户端消息
	register.RegisterSocketHandler(defines.Opcode_SC_GET_RESOURCES, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_GetResources{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_GET_ROOM_INFO, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_GetRoomInfo{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_UPDATE_ROOM_INFO, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_UpdateRoomInfo{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_GET_ROOM_PMT, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_GetRoomPmtInfo{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_UPDATE_ROOM_PMT, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_UpdateRoomPmtInfo{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_ROOM_PMT_UP_LEVEL, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_UpRoomPmtLevel{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_ROOM_UP_CY_LEVEL, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_UpRoomCyLevel{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_UPDATE_RESOURCES, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_UpdateResources{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_HARVEST_RESOURCES, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_HarvestResources{}), "", "")
	register.RegisterSocketHandler(defines.Opcode_SC_ACTIVE_ROOM, opcode.OpCodeType_Protobuf,
		reflect.TypeOf(protos.S2C_ActiveRoom{}), "", "")
}
